package com.iflytek.management.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.iflytek.management.mapper.ProjectMapper;
import com.iflytek.management.pojo.Project;
import com.iflytek.management.util.MybatisUtil;

@Controller
@RequestMapping(value = "/proj")
public class ProjController {
	
	@RequestMapping(value = "/showAllProj.do",method = RequestMethod.GET)
	@ResponseBody
	public JSONObject showAllMember() throws IOException {
		ProjectMapper mapper = MybatisUtil.Prepare(ProjectMapper.class);
		JSONObject res = new JSONObject();
		List<Project> allProj = new ArrayList<Project>();
		try {
			allProj = mapper.selectAll();
			
		} catch (Exception e) {
			System.out.println(e);
		}
		res.put("allPro", allProj);
		return res;
	}
	
	// 没写完
	@RequestMapping(value = "/toEditProj.do",method = RequestMethod.POST)
	@ResponseBody
	public JSONObject toEditMember(@RequestBody Map<String, Object> parms, HttpSession sess) throws IOException {
		return new JSONObject();
	}
		

	// 添加项目
	@RequestMapping("/addProj.do")
	@ResponseBody
	public JSONObject addProject(@RequestBody Project proj) throws Exception{
		JSONObject res = new JSONObject();
		ProjectMapper projectMapper=MybatisUtil.Prepare(ProjectMapper.class);
		try {
			int i = projectMapper.insert(proj);
			if (i == 1) {
				res.put("msg","添加成功");
				
			}
		} catch (Exception e) {
			// TODO: handle exception
			res.put("msg", "添加失败");
			
		}
		return res;
	}
}